<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@page import="java.util.List"%>
<%@page import="org.quickbundle.project.common.vo.RmCommonVo"%>
<%@page import="org.quickbundle.project.RmProjectHelper"%>
<%@page import="java.util.HashMap"%>
<%@page import="com.dfhc.util.CryptoHelper"%>
<%@page import="java.util.Map"%>
<%@page import="org.quickbundle.tools.helper.RmJspHelper"%>
<%@page import="org.quickbundle.orgauth.IOrgauthConstants"%>
<html>
<head>
<title>rm-based architecture project</title>
<%-- <%@ include file="/jsp/include/rmGlobal.jsp" %> --%>
<jsp:include page="/jsp/support/deeptree/include/globalDeepTree.jsp" />
<%@ taglib uri="/dfhc" prefix="dfhc" %>
<!-- 全局js 和css包 -->
<%@ include file="/jsp/include/web/new/global.jsp" %>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/ztree/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/ztree/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/ztree/jquery.ztree.excheck-3.5.js"></script>
				<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/h-ui.admin/zTreeStyle/zTreeStyle.css" />
<script type="text/javascript">

</script>
</head>
<body >

<dfhc:div templateId="h_ui_ztree_div"  id="treeDemo" >
</dfhc:div>

</body>
<script type="text/javascript">
var totalCode='';
var setting = {
	async: {
	enable: true,
	url:'<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/pubController/getMenuTree")%>?cmd=roleData&is_href=1&reference=1&enableCookie=true&lazy_init=1',
	autoParam:["total_code"],
	otherParam:{},
	dataFilter: filter
  },
  callback: {
	  beforeClick: beforeClick,
	  beforeAsync: beforeAsync,
	  onAsyncError: onAsyncError,
	  onAsyncSuccess: onAsyncSuccess
	  }
};
function filter(treeId, parentNode, childNodes) {
	if (!childNodes) return null;

	var childNodes= childNodes.lcvo;
	if(childNodes.length==0){
		childNodes.name='无数据';
		}
	for (var i=0, l=childNodes.length; i<l; i++) {
		//if(childNodes[i].total_code.length<7){
		//	childNodes[i].isParent=true;
		//	}
		if(childNodes[i].is_leaf=='1'){
			childNodes[i].isParent=false;
		}else{
			childNodes[i].isParent=true;
		}
		childNodes[i].url='<%=request.getContextPath()%><%=CryptoHelper.encryptUrl(request,"/rmFunctionNode/detail")%>?id='+childNodes[i].id;
		childNodes[i].target='operation_frame';
		childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
	}
	return childNodes;
}
function beforeClick(treeId, treeNode) {
	totalCode=treeNode.total_code;
	//alert(totalCode)
	//if(totalCode.length<7){
	//	treeNode.isParent=true;
	//	}
	if(treeNode.is_leaf=='1'){
			treeNode.isParent=false;
		}else{
			treeNode.isParent=true;
		}
	if (!treeNode.isParent) {
		return false;
	} else {
		return true;
	}
}
var log, className = "dark";
function beforeAsync(treeId, treeNode) {
	className = (className === "dark" ? "":"dark");
	showLog("[ "+getTime()+" beforeAsync ]&nbsp;&nbsp;&nbsp;&nbsp;" + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") );
	return true;
}
function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
	showLog("[ "+getTime()+" onAsyncError ]&nbsp;&nbsp;&nbsp;&nbsp;" + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") );
}
function onAsyncSuccess(event, treeId, treeNode, msg) {
	showLog("[ "+getTime()+" onAsyncSuccess ]&nbsp;&nbsp;&nbsp;&nbsp;" + ((!!treeNode && !!treeNode.name) ? treeNode.name : "root") );
}

function showLog(str) {
	if (!log) log = $("#log");
	log.append("<li class='"+className+"'>"+str+"</li>");
	if(log.children("li").length > 8) {
		log.get(0).removeChild(log.children("li")[0]);
	}
}
function getTime() {
	var now= new Date(),
	h=now.getHours(),
	m=now.getMinutes(),
	s=now.getSeconds(),
	ms=now.getMilliseconds();
	return (h+":"+m+":"+s+ " " +ms);
}

function refreshNode(e) {
	var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
	type = e.data.type,
	silent = e.data.silent,
	nodes = zTree.getSelectedNodes();
	if (nodes.length == 0) {
		alert("请先选择一个父节点");
	}
	for (var i=0, l=nodes.length; i<l; i++) {
		zTree.reAsyncChildNodes(nodes[i], type, silent);
		if (!silent) zTree.selectNode(nodes[i]);
	}
}

$(document).ready(function(){
	$.fn.zTree.init($("#treeDemo"), setting);
	$("#refreshNode").bind("click", {type:"refresh", silent:false}, refreshNode);
	$("#refreshNodeSilent").bind("click", {type:"refresh", silent:true}, refreshNode);
	$("#addNode").bind("click", {type:"add", silent:false}, refreshNode);
	$("#addNodeSilent").bind("click", {type:"add", silent:true}, refreshNode);
});
function qd(){//确认

 	window.close();
}

</script>
</html>